﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FA.Library.ExtensionMethods
{
    /// <summary>
    /// Extension methods to provide additional functionality to existing types.
    /// </summary>
    public static class ExtensionMethods
    {
        /// <summary>
        /// Equality comparator for IDictionary types.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public static bool CheckForEquality<T1, T2>(this IDictionary<T1, T2> source, IDictionary<T1, T2> destination)
        {
            if (destination == null || source.Count() != destination.Count())
            {
                return false;
            }

            foreach (KeyValuePair<T1, T2> kvp in source)
            {
                // Check if the key exists and the value is the same
                if (!destination.ContainsKey(kvp.Key) || !destination[kvp.Key].Equals(kvp.Value))
                {
                    return false;
                }
            }

            return true;
        }
    }
}
